<script>
function Promise(executor){
    var self = this
    self.status = 'pending'
    self.data = undefined
    self.onResolvedCallback = []
    self.onRejectedCallback = []
    function resolve(value){
        if(self.status === 'pending'){
            self.status = 'resolved'
            self.data = value
            for(var i = 0; i < self.onResolvedCallback.length; i++){
                self.onResolvedCallback[i](value)
            }
        }
    }
    function reject(reason){
        if(self.status === 'pending'){
            self.status = 'rejected'
            self.data = reason
            for(var i = 0; i < self.onRejectedCallback.length; i++){
                self.onRejectedCallback[i](reason)
            }
        }
    }
    try{
        executor(resolve,reject)
    }catch(e){
        reject(e)
    }
}

Promise.prototype.then = function(resolve,reject){
    this.onResolvedCallback.push(resolve)
    this.onRejectedCallback.push(reject)
}

let promise = new Promise((resolve,reject) => {
    resolve(1)
})

console.log(promise);

</script>